#include <cserver/restapi.h>
#include <boost/log/trivial.hpp>
#include <boost/lexical_cast.hpp>
#include <pqxx/transaction.hxx>
#include <boost/format.hpp>

#include <sstream>

namespace csrv{ namespace webcmd{
	static const char* K_this_command= "api/v1/light/get_pole";


	void light_get_pole(Request& req, pqxx::connection& dbconn, SessionContext& , const std::string& /*cmd*/ ){
		auto query = parseQuery(req.getParam("QUERY_STRING"));
		auto& callback = query["callback"];
		auto& id = query["id"];

		StreamGroup sg(req);
		auto& fout = sg.fout;
		response_header(sg.fout, 200);
		if (!callback.empty()) sg.fout << callback << "(";

#if 1
		fout << boost::format(R"({"func":"list/get_pole",
"args":{},
"ret":{"success":true, "message":"",
"value":)");
#endif
		pqxx::work w(dbconn);
		auto result = w.prepared("get_pole")(id).exec();
		fout << result2json(result, 2);
		fout << "}}";
		
		if (!callback.empty()) sg.fout << ")";
	}
}

static CommandAddHelper k_registerHandler("GET", webcmd::K_this_command, &webcmd::light_get_pole);
}

